﻿//
//  Windows_libc
//
//  Created by  cc_team(陈旭，陈曦) qq:511272827.
//  Copyright 2011 cc_team. All rights reserved.
//
#ifndef CC_STRING_H
#define CC_STRING_H

#define IS_STR_EQUAL(str1, str2)	(cc_strcmp(str1, str2) == 0)

extern char *keywordsArr[];
extern int keywordsCnt;

#include "cc_common.h"
#include "cc_stdlib.h"

#define	    INOUT

#ifdef __cplusplus
extern "C" {
#endif

char * __cdecl cc_strcat(
	char *dest,
	const char *src
);

char * __cdecl cc_strcpy(
	char *dest,
	const char *src
);

char * __cdecl cc_strchr(
	const char *str,
	int ch
	);

int __cdecl cc_strcmp(
	const char *str1,
	const char *str2
);

// strcmp, and ignore the upper or lower case
int __cdecl cc_stricmp(
	const char *str1,
	const char *str2
	);

size_t __cdecl cc_strlen(
	const char *str
);

size_t __cdecl cc_strnlen(
	const char *str,
	size_t maxSize
);

char * __cdecl cc_strncat(
	char *dest,
	const char *src,
	size_t cnt
	);

int __cdecl cc_strncmp(
	const char *str1,
	const char *str2,
	size_t cnt
);

size_t __cdecl cc_strncnt(
	const char *str,
	size_t cnt
);

char * __cdecl cc_strncpy(
	char *dest,
	const char *src,
	size_t cnt
	);

char * __cdecl cc_strstr(
	const char *src1,
	const char *src2
);

char * __cdecl cc_strtok(
	char *str,
	const char *delim
	);

// duplicate a string
char * __cdecl cc_strdup(
	const char *str
);

// skip the blank characters in the front of a string, such as ' ', '\t', '\n'
// returnValue: the first non-blank char pointer
void * __cdecl cc_skipBlankCharacters(INOUT const void **strHead);

// get whether the str is an identifier or not
int __cdecl cc_isIdentifier(const char *str);
int __cdecl cc_isIdentifierFirstChar(int ch);
int __cdecl cc_isIdentifierAfterFirstChar(const char *str);

// can ignore upper or lower case alpha chars
int __cdecl cc_canIgnoreUpperLowerCase(
	const int ch1,
	const int ch2
);

char * __cdecl cc_strnset(
	char *str,
	int val,
	size_t cnt
);

// reverse a string, "xichen2" to "2nehcix"
char * __cdecl cc_strrev(
	char *str
);

// whether the str is a keyword, of course, the keywords of standard C programming language
int __cdecl cc_isKeyword(
	const char *str
);

// whether a str is a binary number str, like "111", "100", "011" and so on
int __cdecl cc_isBinaryNum(
	const char *str
);

// whether a str is a oct number str, like "777", "100", "27" and so on
int __cdecl cc_isOctNum(
	const char *str
);

// whether a str is a decimal number str, like "999", "-134", "100" and so on
int __cdecl cc_isDecNum(
	const char *str
);

// whether a str is a hex number str, like "FFF", "134" , "0x12", "0xAF", "B6", "A8" and so on
int __cdecl cc_isHexNum(
	const char *str
);

// remove the blank chars at the begin of the str; NB. it will modify the str.
// returns: the new str.
char * __cdecl cc_trimBegin(
	char *str
);

// remove the blank chars at the end of the str; NB. it will modify the str.
// returns: the new str.
char * __cdecl cc_trimEnd(
	char *str
);

// remove the blank chars at the begin and the end of the str; NB. it will modify the str.
// returns: the new str.
char * __cdecl cc_trim(
	char *str
);

// whether a str begins with another str
int __cdecl cc_strBeginsWith(
	const char *str,
	const char *anotherStr
);

// whether a str ends with another str
int __cdecl cc_strEndsWith(
	const char *str,
	const char *anotherStr
);

// find the first char which equals to the indicated char in the str, if none, returns -1
int __cdecl cc_strIndexOf(
	const char *str,
	char ch
);

// find the last char which equals to the indicated char in the str, if none, returns -1;
// NB.the return value is alse calculated from the str begin.
int __cdecl cc_strLastIndexOf(
	const char *str,
	char ch
);

// find the pointer in str that equals to the patternStr;if none, return NULL
char * __cdecl cc_strIndexOfStr(
	const char *str,
	const char *patternStr
);

// get the length of a str converted from a number, ie, number 100 returns 3
int __cdecl cc_getNumLenByStr(
	unsigned n
);

// convert the str to the upper case str
void __cdecl cc_toUpperStr(
	char *str
);

// convert the str to the lower case str
void __cdecl cc_toLowerStr(
	char *str
);

// delete all the indicated chars in a str,ie,"cdcd", delete the 'c', then the result is "dd"
// NB.it will modify the str.
// returns: the modified str.
char * __cdecl cc_delChar(
	char *str,
	char ch
); 

#ifdef __cplusplus
}		// extern "C"
#endif

#endif	// CC_STRING_H